<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>PHP Write to File - fopen()</title>
</head>
<body>
<h1>PHP Write to File - fopen()</h1>

<div>
    <h3>PHP Create File - fopen()</h3>
    <?php
    $myfile = fopen("testfile.txt", "w");
    var_dump($myfile);
    fclose($myfile);
    ?>
</div>
<!--<div>
    <h3>PHP Write to File - fwrite()</h3>
    <?php
/*    $myfile = fopen("testfile.txt", "w");
    $txt = "John Doe\r\n";
    fwrite($myfile,$txt);
    $txt = "Jane Doe\r\n";
    fwrite($myfile,$txt);
    fclose($myfile);

    $myfile = fopen("testfile.txt", "r");
    $content = fread($myfile,filesize("testfile.txt"));
    echo("<pre>$content<pre/>");
    */?>
</div>-->
<div>
    <h3>PHP Overwriting</h3>
    <?php
    $myfile = fopen("testfile.txt", "w");
    $txt = "Mickey Mouse\r\n";
    fwrite($myfile, $txt);
    $txt = "Minnie Mouse\r\n";
    fwrite($myfile, $txt);
    fclose($myfile);

    $myfile = fopen("testfile.txt", "r");
    $content = fread($myfile, filesize("testfile.txt"));
    echo("<pre>$content<pre/>");
    ?>
</div>
</body>
</html>